// store/modules/user.ts
import { defineStore, type StoreDefinition } from 'pinia';

export interface UserStoreInterface{
  token: string | null,
  userInfo: any
}
export interface UserStoreGettersInterface{
  token: string | null,
  userInfo: any
}
export interface UserStoreActionssInterface{
  setToken: (value:string)=>void,
  userInfo: (value:any)=>void,
}
//@ts-ignore
export const useUserStore: StoreDefinition<"userStore", UserStoreInterface, UserStoreGettersInterface, UserStoreActionssInterface> = defineStore('userStore', {
  state: () :UserStoreInterface => ({
    token: null,
    userInfo: {}
  }),
  getters: {
    isLoginState: (state:UserStoreInterface) => state.token!=null,
  },
  actions: {
    setToken(token:string){this.token=token},
    setUserInfo(userInfo:any){this.userInfo=userInfo},
  },
  persist: {
    enabled: true , // 这个配置代表存储生效，而且是整个store都存储
  }
});
